﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;

namespace Fulcrum.ViewModelGenerator.UnitTests
{
    [TestClass]
    public class TestSample3Tests
    {
        public TestSample3Tests()
        {
            // nothing
        }

        DependencyObject testObject;

        [TestInitialize]
        public void TestInitialize()
        {
            TestSample3.ClearValues();
            this.testObject = new DependencyObject();
        }

        [TestMethod]
        public void TestSample3_AttachedInt_DefaultValue()
        {
            var value = TestSample3.GetAttachedInt(this.testObject);

            Assert.AreEqual(15, value);
        }

        [TestMethod]
        public void TestSample3_AttachedInt_Set()
        {
            TestSample3.SetAttachedInt(this.testObject, 9812739);

            var value = TestSample3.GetAttachedInt(this.testObject);

            Assert.AreEqual(9812739, value);
        }

        [TestMethod]
        public void TestSample3_AttachedInt_ChangedCallback()
        {
            Assert.AreEqual(0, TestSample3.AttachedIntChangedCalledCount);

            TestSample3.SetAttachedInt(this.testObject, 17);

            Assert.AreEqual(1, TestSample3.AttachedIntChangedCalledCount);
            Assert.AreSame(this.testObject, TestSample3.AttachedIntObject);
            Assert.AreEqual(17, TestSample3.AttachedIntChangedEventArgs.NewValue);
            Assert.AreEqual(15, TestSample3.AttachedIntChangedEventArgs.OldValue);
            Assert.AreEqual(TestSample3.AttachedIntProperty, TestSample3.AttachedIntChangedEventArgs.Property);
        }

        [TestMethod]
        public void TestSample3_AttachedInt_Validate_Valid()
        {
            TestSample3.AttachedIntValidValue = null;

            Assert.AreEqual(0, TestSample3.AttachedIntValidateCalledCount);

            TestSample3.SetAttachedInt(this.testObject, 17);

            Assert.AreEqual(1, TestSample3.AttachedIntValidateCalledCount);
            Assert.AreEqual(17, TestSample3.AttachedIntValidateValue);

            var value = TestSample3.GetAttachedInt(this.testObject);
            Assert.AreEqual(17, value);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestSample3_AttachedInt_Validate_Invalid()
        {
            TestSample3.AttachedIntValidValue = 342;

            Assert.AreEqual(0, TestSample3.AttachedIntValidateCalledCount);

            TestSample3.SetAttachedInt(this.testObject, 17);
        }

        [TestMethod]
        public void TestSample3_ROAttachedInt_DefaultValue()
        {
            var value = TestSample3.GetROAttachedInt(this.testObject);

            Assert.AreEqual("", value);
        }

        [TestMethod]
        public void TestSample3_ROAttachedInt_Set()
        {
            TestSample3.SetROAttachedIntPublic(this.testObject, "9812739");

            var value = TestSample3.GetROAttachedInt(this.testObject);

            Assert.AreEqual("9812739", value);
        }

        [TestMethod]
        public void TestSample3_ROAttachedInt_ChangedCallback()
        {
            Assert.AreEqual(0, TestSample3.ROAttachedIntChangedCalledCount);

            TestSample3.SetROAttachedIntPublic(this.testObject, "17");

            Assert.AreEqual(1, TestSample3.ROAttachedIntChangedCalledCount);
            Assert.AreSame(this.testObject, TestSample3.ROAttachedIntObject);
            Assert.AreEqual("17", TestSample3.ROAttachedIntChangedEventArgs.NewValue);
            Assert.AreEqual("", TestSample3.ROAttachedIntChangedEventArgs.OldValue);
            Assert.AreEqual(TestSample3.ROAttachedIntProperty, TestSample3.ROAttachedIntChangedEventArgs.Property);
        }
    }
}
